2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Graphics;
7 using Microsoft.Xna.Framework.Content;
8 using System.Security.Cryptography;
10 namespace SuperPolarity
12 class StandardShip : Ship
15 protected int ChangeRate;
16 protected int CurrentTime;
17 protected int AngleChangeProbability;
18 protected int BouncePadding;
19 protected float RotationFactor;
20 protected Random Random;
21 protected bool AddingAngle;
23 public StandardShip(Game newGame) : base(newGame) {}
25 public override void Initialize(Texture2D texture, Vector2 position)
27 base.Initialize(texture, position);
29 var cryptoResult = new byte[4];
30 new RNGCryptoServiceProvider().GetBytes(cryptoResult);
33 AngleChangeProbability = 50;
37 RotationFactor = (float) (3 * Math.PI / 180);
38 Random = new Random(BitConverter.ToInt32(cryptoResult, 0));
42 public override void Magnetize(Ship ship, float distance, float angle)
44 if (ship.GetType() == typeof(MainShip)) {
45 base.Magnetize(ship, distance, angle);
49 public override void Update(GameTime gameTime)
51 CurrentTime += gameTime.ElapsedGameTime.Milliseconds;
62 protected void AutoMove()
64 float newAngle = Angle;
66 if (CurrentTime < ChangeRate)
71 if (Random.Next(AngleChangeProbability) == 2)
73 AddingAngle = !AddingAngle;
80 newAngle += (float) ( Random.NextDouble() * RotationFactor);
84 newAngle -= (float) (Random.NextDouble() * RotationFactor);
87 Velocity.X = (float) (MaxVelocity * Math.Cos(newAngle));
88 Velocity.Y = (float) (MaxVelocity * Math.Sin(newAngle));
91 protected void BounceBack()
93 if (Position.X + Width < -BouncePadding && Velocity.X < 0)
95 Velocity.X = -Velocity.X;
98 if (Position.Y + Height < -BouncePadding && Velocity.Y < 0)
100 Velocity.Y = -Velocity.Y;
103 if (Position.X > game.GraphicsDevice.Viewport.Width + BouncePadding && Velocity.X > 0)
105 Velocity.X = -Velocity.X;
108 if (Position.Y > game.GraphicsDevice.Viewport.Height + BouncePadding && Velocity.Y > 0)
110 Velocity.Y = -Velocity.Y;